package com.bw.merchant.page.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.path.RouterPath
import com.bw.common.view.BaseMvvmFragment
import com.bw.merchant.R
import com.bw.merchant.adapter.RecordingAdapter
import com.bw.merchant.databinding.FragmentRecordingBinding
import com.bw.merchant.vm.MerchantViewModel
import dagger.hilt.android.AndroidEntryPoint

/**
 * 申请记录
 */
@AndroidEntryPoint
class RecordingFragment : BaseMvvmFragment<FragmentRecordingBinding>() {
    override fun getLayoutId(): Int = R.layout.fragment_recording
    private val mViewModel:MerchantViewModel by activityViewModels()
    val mAdapter = RecordingAdapter()
    override fun initView() {
        mDataBinding.recordingRv.adapter = mAdapter

        mViewModel.mRecordingSuccess.observe(this){
            mAdapter.data.addAll( it.sortedByDescending { it.id })
            mAdapter.notifyDataSetChanged()
        }

        mAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build(RouterPath.PATH_APPROVAL_DETAIL_PATH)
                .withInt("iid",mAdapter.data[position].id)
                .navigation()
        }
    }

    override fun loadData() {
        super.loadData()
        mViewModel.getRecordingData()
    }


}